<template>
	<view class="container">
		<u-toast ref="uToast" />
		<u-navbar :is-back="false" title="校园生活" back-icon-color='#333333' height="50" :border-bottom="false">
		</u-navbar>
		<swiper :autoplay="true" style="margin-top:20rpx;" :interval="3000" :duration="1000" :indicator-dots="true"
			indicator-active-color="#fff">
			<swiper-item>
				<image src="../../static/tupian131.png" mode="widthFix" style="width: 100%;"> </image>
			</swiper-item>
			<swiper-item>
				<image src="../../static/tupian131.png" mode="widthFix" style="width: 100%;"> </image>
			</swiper-item>
		</swiper>
		<view class="teacherList">
			<view class="teacher_dynamic" @click="$toLink('../my_tidings/my_tidings',{})">
				<text>老师动态</text>
				<image src="../../static/tupian93.png" mode="widthFix"> </image>
			</view>
			<view class="teacher" v-for="(item,index) in dynamic_list" :key="index">
				<view class="top">
					<view class="left_img">
						<image :src="item.dynamicUrl" mode="widthFix"> </image>
					</view>
					<view class="right_content">
						<view class="">
							<text style="overflow:hidden;">{{item.teacher_info.full_name}}</text>
							<text>(初一语文)</text>
						</view>
						<view class="">
							<text>{{item.text}}</text>
						</view>
					</view>
				</view>
				<view class="imgList">
					<image :src="i" mode="widthFix" v-for="(i,j) in item.photoList" :key="j"></image>
				</view>
				<view class="time">
					<text>{{item.dynamic_time}}</text>
					<image src="../../static/tupian132.png" mode="widthFix"></image>
				</view>
				<view class="comment">
					<view class="like" v-for="(ele,num) in item.like_name_arr" :key="num">
						<image src="../../static/tupian133.png" mode="widthFix"></image>
						<text>{{ele}}</text>
					</view>
					<view class="discuss">
						<view class="" v-for="(h,g) in item.comment_lists" :key="g">
							<text>{{h.user_info?h.user_info.full_name:''}}:</text>
							<text>{{h.content}}</text>
						</view>
					</view>
				</view>
				<view class="" style="width:710rpx; height:30rpx; margin-left:20rpx;border-bottom:1rpx solid #e5e5e5;">
				</view>
				<view class="" style="width:100%; height:30rpx;">
				</view>
			</view>
		</view>
		<view class="campus_info">
			<view class="latest_campus" @click="$toLink('../campus_news/campus_news',{})">
				<text>最新校园资讯</text>
				<image src="../../static/tupian93.png" mode="widthFix"> </image>
			</view>
			<view id="campus_list">
				<view class="per_campus"
					@click="$toLink('../information_details/information_details',{id:item.school_news_id})"
					v-for="(item,index) in schoolNews" :key="index">
					<view class="left_pic">
						<image :src="item.picsUrl" mode="widthFix"></image>
					</view>
					<view class="right_campus">
						<view class="caption">
							<text>{{item.title}}</text>
						</view>
						<view class="matter">
							{{item.text}}
						</view>
						<view class="ms">
							<text>{{item.create_time}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-mask :show="show">
			<view class="wrap">
				<view class="rect" @tap.stop>
						<view id="icon">
							<view class="notice" @click="$toLink('../release_notice/release_notice',{})">
								<image src="../../static/tupian16.png" mode="widthFix"></image>
								<text>发布通知</text>
							</view>
							<view id="dynamic">
								<image src="../../static/tupian16.png" mode="widthFix"></image>
								<text>发布动态</text>
							</view>
							<view id="email" @click="$toLink('../compose_email/compose_email',{})">
								<image src="../../static/tupian17.png" mode="widthFix"></image>
								<text>发布邮件</text>
							</view>
							<view id="course" @click="$toLink('../add_course/add_course',{})">
								<image src="../../static/tupian23.png" mode="widthFix"></image>
								<text>发送课件</text>
							</view>
							<view id="upload" @click="$toLink('../upload_photos/upload_photos',{})">
								<image src="../../static/tupian45.png" mode="widthFix"></image>
								<text>上传图片</text>
							</view>
							<image src="../../static/tupian146.png" mode="widthFix" id="del" @click.stop="hide"></image>
							<view class="hump">
							</view>
						</view>
				</view>
			</view>
		</u-mask>
		<u-tabbar :list="list" active-color="#2491FE" :mid-button="true" @change="changeIndex"></u-tabbar>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import request from '../../request.js'
	import time from '../../time.js'

	export default {
		data() {
			return {
				left_url: '../../static/tupian101.png',
				right_url: '../../static/tupian102.png',
				school_news: [],
				dynamicList: [],
				show:false,
			}
		},
		onLoad() {
			this.getSchoolNews();
			this.getSchoolNewsMomentLists();
		},
		computed: {
			...mapState(['list']),
			schoolNews() {
				if (this.school_news) {
					this.school_news.forEach(item => {
						this.$set(item, 'picsUrl', `${uni.getStorageSync('host')}${item.pics}`);
					})
					return this.school_news;
				} else {
					return [];
				}
			},
			dynamic_list() {
				if (this.dynamicList) {
					this.dynamicList.forEach(item => {
						this.$set(item, 'dynamicUrl', `${uni.getStorageSync('host')}${item.teacher_info
.avatar_img}`)
						this.$set(item, 'dynamic_time', time.format(item.create_time));
						this.$set(item, 'photoList', item.pics.split(','))
					})
					return this.dynamicList;
				} else {
					return [];
				}
			}

		},
		methods: {
			getSchoolNews() {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				request({
					url: base_url + 'teacher/schoolNews/lists',
					method: 'post',
					data: {
						type: ""
					},
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data.data);
							_this.school_news = res.data.data.data;
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			changeIndex(e) {
				console.log(e);
				switch (e) {
					case 2:
						this.show = !this.show;

				}
			},
			hide(){
				this.show = !this.show;
			},
			getSchoolNewsMomentLists() {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				request({
					url: base_url + 'teacher/moment/momentLists',
					method: 'post',
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data.data);
							_this.dynamicList = res.data.data.data;
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
		}

	}
</script>

<style lang="scss">
	.container {
		width: 100%;
		background: #F2F2F2;

		.teacherList {
			width: 100%;
			margin-top: 20rpx;
			background: #fff;

			.teacher_dynamic {
				height: 100rpx;
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: flex-start;

				text {
					&:nth-child(1) {
						color: #333333;
						font-size: 30rpx;
						width: 680rpx;
						margin-left: 20rpx;
					}
				}

				image {
					&:nth-child(2) {
						width: 20rpx;
					}
				}

			}

			.teacher {
				width: 100%;
				background: #fff;

				.top {
					width: 100%;
					height: 121rpx;
					display: flex;
					justify-content: flex-start;

					.left_img {
						width: 111rpx;
						height: 121rpx;
						display: flex;
						justify-content: center;

						image {
							width: 60rpx;
						}
					}

					.right_content {
						width: 630rpx;
						view {
							&:nth-child(1) {
								width: 100%;
								height: 32rpx;
								display: flex;
								justify-content: flex-start;
								align-items: center;
								overflow: hidden;

								text {
									font-size: 30rpx;
									color: #5b6a91;

									&:nth-child(1) {
										width: 120rpx;
									}

									&:nth-child(2) {}
								}
							}

							&:nth-child(2) {
								width: 100%;
								margin-top: 30rpx;
								height: 28rpx;
								display: flex;
								justify-content: flex-start;
								align-items: center;

								text {
									font-size: 26rpx;
									color: #333333;

									&:nth-child(1) {
										width: 100%;
										overflow: hidden;
									}
								}
							}
						}
					}

				}

				.imgList {
					width: 100%;
					// height: 153rpx;
					flex-wrap: wrap;
					margin-top: 0;
					display: flex;
					justify-content: flex-start;

					image {
						margin-top: 0;



						&:nth-child(n+1) {
							margin-left: 30rpx;
							width: 153rpx;
							height: 153rpx;
						}

						&:nth-child(1) {
							margin-left: 111rpx;
							width: 153rpx;
							height: 153rpx;
						}

						&:nth-child(n+3) {
							margin-top: 10rpx;
						}

						&:nth-child(4) {
							margin-left: 111rpx;
							width: 153rpx;
							height: 153rpx;
						}

					}
				}

				.time {
					width: 100%;
					height: 69rpx;
					display: flex;
					justify-content: flex-start;

					text {
						&:nth-child(1) {
							margin-top: 27rpx;
							font-size: 22rpx;
							margin-left: 111rpx;
							color: #b7b7b7;
							width: 550rpx;
						}
					}

					image {
						&:nth-child(2) {
							width: 64rpx;
							margin-top: 22rpx;
						}
					}

				}

				.comment {
					width: 620rpx;
					margin-left: 111rpx;
					background: #f8f8f8;

					.like {
						width: 100%;
						height: 65rpx;
						box-sizing: border-box;
						border-bottom: 1rpx solid #e5e5e5;
						display: flex;
						align-items: center;
						justify-content: flex-start;

						image {
							&:nth-child(1) {
								width: 24rpx;
								margin-left: 15rpx;
							}
						}

						text {
							&:nth-child(2) {
								font-size: 24rpx;
								margin-left: 17rpx;
								color: #5b6a91;
							}
						}
					}

					.discuss {
						width: 100%;

						view {
							width: 100%;
							height: 65rpx;
							box-sizing: border-box;
							display: flex;
							align-items: center;
							justify-content: flex-start;

							text {
								&:nth-child(1) {
									font-size: 24rpx;
									margin-left: 15rpx;
									color: #5b6a91;
								}

								&:nth-child(2) {
									font-size: 24rpx;
									margin-left: 15rpx;
									color: #666666;
								}
							}
						}
					}
				}


			}
		}

		.campus_info {
			width: 100%;
			background: #fff;
			margin-top: 20rpx;

			.latest_campus {
				width: 100%;
				height: 90rpx;
				display: flex;
				align-items: center;
				justify-content: flex-start;

				text {
					&:nth-child(1) {
						width: 680rpx;
						font-size: 30rpx;
						margin-left: 20rpx;
						color: #333333;
					}
				}

				image {
					&:nth-child(2) {
						width: 20rpx;
					}
				}
			}

			#campus_list {
				width: 100%;

				.per_campus {
					width: 710rpx;
					margin-left: 20rpx;
					height: 190rpx;
					border-bottom: 1rpx solid #e5e5e5;
					display: flex;
					justify-content: flex-start;

					.left_pic {
						width: 203rpx;
						height: 147rpx;
						margin-top: 22rpx;
						overflow: hidden;

						image {
							&:nth-child(1) {
								width: 203rpx;
							}
						}
					}

					.right_campus {
						width: 485rpx;
						margin-top: 25rpx;
						height: 165rpx;
						overflow: hidden;
						margin-left: 22rpx;

						.caption {
							margin-top: 3rpx;
							width: 100%;

							text {
								&:nth-child(1) {
									color: #333333;
									font-size: 26rpx;
								}
							}
						}

						.matter {
							width: 100%;
							margin-top: 10rpx;
							color: #666666;
							font-size: 24rpx;
						}

						.ms {
							width: 100%;
							height: 21rpx;
							margin-top: 0rpx;

							text {
								color: #999999;
								font-size: 21rpx;

								&:nth-child(1) {
									width: 120rpx;
								}

								&:nth-child(2) {}
							}
						}
					}
				}

			}

		}

		.wrap {
			width: 100%;
			display: flex;
			align-items: flex-end;
			justify-content: center;
			height: 100%;
			.rect {
				margin-bottom: 150rpx;
				width: 710rpx;
				height: 377rpx;
				border-radius: 20rpx;
					#icon {
						height: 357rpx;
						background: #fff;
						width:100%;
						border-radius: 20rpx;
						position: relative;
				
						.hump {
							width: 220rpx;
							height: 120rpx;
							position: absolute;
							left:245rpx;
							top: 248rpx;
							background: #fff;
							border-radius: 50%;
						}
				
						.notice {
							width: 130rpx;
							height: 105rpx;
							left: 77rpx;
							top: 40rpx;
							position: absolute;
							z-index: 100;
							display: flex;
							justify-content: flex-start;
							flex-direction: column;
							align-items: center;
				
							image {
								&:nth-child(1) {
									width: 47rpx;
								}
							}
				
							text {
								&:nth-child(2) {
									margin-top: 20rpx;
									color: #333333;
									font-size: 30rpx;
								}
							}
						}
				
						#dynamic {
							width: 130rpx;
							height: 105rpx;
							left: 291rpx;
							top: 40rpx;
							position: absolute;
							z-index: 100;
							display: flex;
							justify-content: flex-start;
							flex-direction: column;
							align-items: center;
				
							image {
								&:nth-child(1) {
									width: 47rpx;
								}
							}
				
							text {
								&:nth-child(2) {
									margin-top: 20rpx;
									color: #333333;
									font-size: 30rpx;
								}
							}
						}
				
						#email {
							width: 130rpx;
							height: 105rpx;
							left: 505rpx;
							top: 40rpx;
							position: absolute;
							z-index: 100;
							display: flex;
							justify-content: flex-start;
							flex-direction: column;
							align-items: center;
				
							image {
								&:nth-child(1) {
									width: 45rpx;
									margin-top: 5rpx;
								}
							}
							text {
								&:nth-child(2) {
									margin-top: 25rpx;
									color: #333333;
									font-size: 30rpx;
								}
							}
						}
				
						#course {
							width: 130rpx;
							height: 105rpx;
							left: 140rpx;
							top: 180rpx;
							position: absolute;
							z-index: 100;
							display: flex;
							justify-content: flex-start;
							flex-direction: column;
							align-items: center;
				
							image {
								&:nth-child(1) {
									width: 47rpx;
								}
							}
				
							text {
								&:nth-child(2) {
									margin-top: 20rpx;
									color: #333333;
									font-size: 30rpx;
								}
							}
						}
				
						#upload {
							width: 130rpx;
							height: 105rpx;
							left: 440rpx;
							top: 180rpx;
							position: absolute;
							z-index: 100;
							display: flex;
							justify-content: flex-start;
							flex-direction: column;
							align-items: center;
				
							image {
								&:nth-child(1) {
									width: 47rpx;
								}
							}
				
							text {
								&:nth-child(2) {
									margin-top: 20rpx;
									color: #333333;
									font-size: 30rpx;
								}
							}
						}
				
						#del {
							width: 51rpx;
							position: absolute;
							z-index: 1000;
							left: 330rpx;
							top: 305rpx;
						}
				
					}

			}
		}
	}
</style>
